package com.android.bookgarden.views;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TextView;

import com.android.bookgarden.R;


/**
 *
 * Created by zouqh on 2018/4/13.
 */

public class SelectPicDialog extends Dialog {
    private View view;
    private DialogCallBack callBack;
    TextView selectAlbum;
    TextView filmingPic;
    public SelectPicDialog(Context context) {
        super(context);

    }

    public SelectPicDialog(Context context, int themeResId, View v, DialogCallBack dialogCallBack) {
        super(context, themeResId);
        this.view = v;
        this.callBack = dialogCallBack;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(view);//这行一定要写在前面
        setCancelable(true);//点击外部不可dismiss
        setCanceledOnTouchOutside(true);
        Window window = this.getWindow();
        window.setGravity(Gravity.BOTTOM);
        WindowManager.LayoutParams params = window.getAttributes();
        params.width = WindowManager.LayoutParams.MATCH_PARENT;
        params.height = WindowManager.LayoutParams.WRAP_CONTENT;
        window.setAttributes(params);
        selectAlbum = view.findViewById(R.id.selectAlbum);
        filmingPic =  view.findViewById(R.id.filmingVideo);
        view.findViewById(R.id.cancel).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                dismiss();
            }
        });
        selectAlbum.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                callBack.selectPic(1);
            }
        });
        filmingPic.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                callBack.selectPic(2);
            }
        });

    }

    public interface DialogCallBack{
        void selectPic(int postion);
    }
}
